<template>
  <div class="qf-regist">
    <van-nav-bar
      title="登录"
      left-text="返回"
      left-arrow
      @click-left="$router.back()"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="form.username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="form.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
        v-model="form.password2"
        type="password"
        name="密码"
        label="密码"
        placeholder="再次确认密码"
        :rules="[{ required: true, message: '请确认密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >注册</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
        password2: "",
      },
    };
  },
  created() {},
  computed: {},
  methods: {
    onSubmit() {
      this.$api.fetchRegist(this.form).then((res) => {
        if (res.err === 0) {
          this.$toast({
            type: "success",
            message: '注册成功',
          });
          this.timer = setTimeout(() => {
            this.$router.replace("/login");
          }, 2000);
        }
      });
    },
    beforeDestroy() {
      clearTimeout(this.timer);
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
